package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckGroupMapper;
import com.itheima.pojo.dto.CheckGroupDTO;
import com.itheima.pojo.entity.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckGroupServiceImpl implements CheckGroupService {

    @Autowired
    private CheckGroupMapper checkGroupMapper;

    @Override
    public List<Integer> findCheckGroupIdsBySetmealId(String setmealId) {
        List<Integer> list=checkGroupMapper.findCheckGroupIdsBySetmealId(Integer.valueOf(setmealId));
        return list;
    }

    @Override
    public PageResult findPageCheckGroup(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<CheckGroup> list=checkGroupMapper.findAll();
        PageInfo<CheckGroup> checkGroupPageInfo = new PageInfo<>(list);
        return new PageResult(checkGroupPageInfo.getTotal(),checkGroupPageInfo.getList());
    }

    @Override
    public void editCheckGroup(CheckGroup checkGroup) {
        checkGroupMapper.updateCheckGroup(checkGroup);
    }

    @Override
    public List<CheckGroup> findAllCheckGroup() {
        List<CheckGroup> list=checkGroupMapper.findAll();
        return list;
    }

    @Override
    public CheckGroup findByIdCheckGroup(String id) {
        CheckGroup checkGroup=checkGroupMapper.findByIdCheckGroup(Integer.valueOf(id));
        return checkGroup;
    }

    @Override
    public void addCheckGroup(CheckGroupDTO checkGroupDTO) {
        CheckGroup checkGroup = new CheckGroup();
        BeanUtils.copyProperties(checkGroupDTO,checkGroup);
        checkGroupMapper.insertCheckGroup(checkGroup);
    }

    @Override
    public void deleteById(String id) {
        checkGroupMapper.deleteById(Integer.valueOf(id));
    }
}
